package modellstadt.rules;

import java.util.ArrayList;
import java.util.Random;

import processing.core.PVector;
import modellstadt.geom.Face;
import modellstadt.parameters.Parameter;

public class RuleLinearSplit extends Rule {
	Parameter split;
	float x1;
	float y1;
	float x2;
	float y2;
	public  RuleLinearSplit(float x1,float y1,float x2,float y2, Parameter minWidth){
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
	}
	@Override
	public ArrayList<Face> replace(Face face, Random seed) {
		// not finished
		// TODO Auto-generated method stub
		float dX=x2-x1;
		float dY=y2-y1;
		PVector d=new PVector(dX,dY);
		d.normalize();
		PVector v2=new PVector(x2,y2);
		PVector cV=new PVector(x1,y1);
		float nextD=split.value(face);
		ArrayList<PVector>points=new ArrayList<PVector>();
		while(v2.dist(cV)>nextD){
			cV=new PVector(cV.x+nextD*d.x,cV.y+nextD*d.y);
			nextD=split.value(face);
			points.add(cV);
		}
		return face.splitByPlanes(points, d);
	}
	
	

}
